package xxl.signals.base.valuelists 
{
	/**
	 * ...
	 * @author XXL
	 */
	public class ArrayValueListAscend 
	{
		public static const NIL:ArrayValueListAscend = new ArrayValueListAscend(null, null);
		
		public var first:ArrayValueListAscend = null;
		public var head:ArrayValueListAscend;
		public var tail:Array;
		public var nonEmpty:Boolean = false;
		
		public function ArrayValueListAscend(tail:Array, head:ArrayValueListAscend = null) 
		{
			if (!head && !tail)
			{
				if (NIL)
				{
					throw new ArgumentError("tail不能为空");
				}
				nonEmpty = false;
			}
			else if (!tail)
			{
				throw new ArgumentError("tail不能为空");
			}
			else
			{
				this.head = head || NIL;
				this.tail = tail;
				nonEmpty = true;
			}
		}
		
		public function append(arr:Array):ArrayValueListAscend
		{
			const headList:ArrayValueListAscend = new ArrayValueListAscend(arr);
			if (first == null)
			{
				headList.first = headList;
				return headList;
			}
			else if (first.head.nonEmpty)
			{
				throw new ArgumentError("不能从中间追加");
			}
			else
			{
				first.head = headList;
				first = headList;
				return this;
			}
		}
		
	}

}